﻿
namespace NavPlus
{
    public class DijkstraNavigation : BaseNavigation
    {
        protected override void DetectNeighborGrid(NavGridLogic detectGrid, NavGridLogic neighborGrid)
        {
            if (!m_CloseLst.Contains(neighborGrid))
            {
                neighborGrid.OnViewChange(ViewState.CheckedPoint);

                float neighborDistance = NavGridLogic.GetLogicGridDistance(detectGrid, neighborGrid);
                float newSumDistance = detectGrid.SumDistance + neighborDistance;

                // 搜索到新节点 或 找到了更优的路径
                if (float.IsPositiveInfinity(neighborGrid.SumDistance)
                    || newSumDistance < neighborGrid.SumDistance)
                {
                    neighborGrid.PreGrid = detectGrid;
                    neighborGrid.SumDistance = newSumDistance;
                }

                if (!m_OpenQue.Contains(neighborGrid))
                {
                    neighborGrid.Priority = neighborGrid.SumDistance;
                    m_OpenQue.Enqueue(neighborGrid);
                }

                neighborGrid.OnViewChange(ViewState.DebugDir);
            }
        }
    }
}